package com.tbq.rebootapk;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.cjj.particle.JJFrie;
import com.cjj.particle.JJSnow;
import com.cjj.particle.JJStar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new JJFrie(MainActivity.this, 100, R.drawable.star, 5000).getFrie(v);
            }
        });
        findViewById(R.id.button1).performClick();


        if(true)
        {
            Intent intent = new Intent(this, CheckAppRunService.class);
            startService(intent);
        }else
        {
            final int pid = getIntent().getIntExtra("pid",0);
            if(pid!=0) {
                Toast.makeText(this, "5秒钟后APP重启", Toast.LENGTH_LONG).show();
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        android.os.Process.killProcess(pid);
                        new Handler().postDelayed(new Runnable() {
                            public void run() {

                                Intent intent = getPackageManager().getLaunchIntentForPackage("com.tbq.tbqj_main"); //打开android自带的视频播放器为例
                                startActivity(intent);
                            }
                        }, 5 * 1000);
                        finish();
                    }
                }, 5 * 1000);
            }else{
                Toast.makeText(this, "5秒钟后重启系统", Toast.LENGTH_LONG).show();

                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        Toast.makeText(MainActivity.this,"重启系统",Toast.LENGTH_LONG).show();
                        RootCmdUtil.execRootCmdSilent(" reboot ");
                    }
                }, 5 * 1000);
            }
        }



    }
}
